package com.zm.demo.core.nio;

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;

import static java.lang.System.out;

/**
 * @author zoum
 * @create 2019/9/16 17:26
 */
public class DatagramChannelReceiveT {


    public static void main(String[] args)throws Exception {

        DatagramChannel channel = DatagramChannel.open();
        channel.socket().bind(new InetSocketAddress(9911));

        ByteBuffer buf = ByteBuffer.allocate(48);
        buf.clear();
        channel.receive(buf);
        while (buf != null){
            out.println("收到消息：" + new String(buf.array()));
        }


    }
}
